package com.samshow.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/8.
 */
@Component
public class LoginSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        Map map1 = new HashMap();
        map1.put("name1","name1");
        Map map2 = new HashMap();
        map2.put("name2","name2");
        List list = new ArrayList();
        list.add(map1);
        list.add(map2);
        ObjectMapper  om = new ObjectMapper();
        String json_str = om.writeValueAsString(list);
        response.getWriter().write(json_str);
        System.out.print("LOGIN SUCCESS------------------");
    }
}
